```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高性能Java并发编程：NIO与JUC深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .table-container {
            overflow-x: auto;
        }
        table {
            min-width: 100%;
            border-collapse: separate;
            border-spacing: 0;
        }
        th {
            background-color: #f8f9fa;
        }
        td, th {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }
        tr:hover td {
            background-color: #f8f9fa;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-2/3">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6">高性能Java并发编程</h1>
                    <h2 class="text-2xl md:text-3xl font-semibold mb-6 text-blue-200">NIO与JUC深度解析</h2>
                    <p class="text-xl mb-8 opacity-90">突破I/O瓶颈 · 释放多核CPU潜力 · 打造高并发系统</p>
                    <div class="flex space-x-4">
                        <span class="inline-flex items-center px-3 py-1 bg-blue-600 rounded-full text-sm font-medium">
                            <i class="fas fa-bolt mr-2"></i>高并发
                        </span>
                        <span class="inline-flex items-center px-3 py-1 bg-blue-600 rounded-full text-sm font-medium">
                            <i class="fas fa-tachometer-alt mr-2"></i>高性能
                        </span>
                        <span class="inline-flex items-center px-3 py-1 bg-blue-600 rounded-full text-sm font-medium">
                            <i class="fas fa-project-diagram mr-2"></i>架构设计
                        </span>
                    </div>
                </div>
                <div class="md:w-1/3 mt-10 md:mt-0">
                    <img src="https://img.icons8.com/color/480/000000/java-coffee-cup-logo.png" alt="Java" class="w-full max-w-xs mx-auto">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-5xl mx-auto px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h3 class="text-2xl font-bold mb-4 text-blue-800 flex items-center">
                    <i class="fas fa-exclamation-circle mr-3"></i>性能优化的核心挑战
                </h3>
                <p class="mb-6 text-gray-700">在现代高并发系统中，性能优化面临三大挑战：</p>
                
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                        <div class="text-red-500 mb-3">
                            <i class="fas fa-tachometer-alt fa-2x"></i>
                        </div>
                        <h4 class="font-bold mb-2">I/O瓶颈</h4>
                        <p class="text-gray-600">传统阻塞I/O导致线程资源浪费</p>
                    </div>
                    <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                        <div class="text-blue-500 mb-3">
                            <i class="fas fa-microchip fa-2x"></i>
                        </div>
                        <h4 class="font-bold mb-2">CPU利用率低</h4>
                        <p class="text-gray-600">上下文切换和锁竞争消耗大量CPU</p>
                    </div>
                    <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                        <div class="text-green-500 mb-3">
                            <i class="fas fa-expand fa-2x"></i>
                        </div>
                        <h4 class="font-bold mb-2">扩展性差</h4>
                        <p class="text-gray-600">系统无法线性扩展以应对流量增长</p>
                    </div>
                </div>
                
                <div class="mt-8 p-4 bg-blue-50 border-l-4 border-blue-500 rounded">
                    <p class="text-blue-800">
                        <i class="fas fa-lightbulb text-blue-500 mr-2"></i>
                        <strong>NIO（Non-blocking I/O）和JUC（Java Util Concurrent）</strong>正是解决这些问题的利器。本文将带你深入理解如何结合NIO和JUC，打造高性能、高并发的Java应用。
                    </p>
                </div>
            </div>
        </section>

        <!-- NIO Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-8 text-blue-800 border-b pb-4 flex items-center">
                    <i class="fas fa-exchange-alt mr-3"></i>
                    <span>NIO：突破I/O性能瓶颈</span>
                </h2>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">传统BIO vs NIO</h3>
                <div class="table-container mb-10">
                    <table>
                        <thead>
                            <tr>
                                <th class="font-semibold text-left">特性</th>
                                <th class="font-semibold text-left">BIO（阻塞I/O）</th>
                                <th class="font-semibold text-left">NIO（非阻塞I/O）</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>线程模型</td>
                                <td>1线程处理1连接</td>
                                <td>1线程处理多连接</td>
                            </tr>
                            <tr>
                                <td>I/O操作</td>
                                <td>阻塞</td>
                                <td>非阻塞</td>
                            </tr>
                            <tr>
                                <td>可扩展性</td>
                                <td>差</td>
                                <td>优秀</td>
                            </tr>
                            <tr>
                                <td>适用场景</td>
                                <td>低并发</td>
                                <td>高并发</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">NIO核心组件</h3>
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="border-l-4 border-blue-500 pl-4">
                        <h4 class="font-bold mb-2">Channel</h4>
                        <p class="text-gray-600">数据通道（如SocketChannel、FileChannel）</p>
                    </div>
                    <div class="border-l-4 border-green-500 pl-4">
                        <h4 class="font-bold mb-2">Buffer</h4>
                        <p class="text-gray-600">数据缓冲区（如ByteBuffer、CharBuffer）</p>
                    </div>
                    <div class="border-l-4 border-purple-500 pl-4">
                        <h4 class="font-bold mb-2">Selector</h4>
                        <p class="text-gray-600">多路复用器，监听多个Channel事件</p>
                    </div>
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">NIO编程模型</h3>
                <div class="code-block p-6 mb-10">
                    <pre><code class="language-java">// 创建Selector
Selector selector = Selector.open();

// 创建ServerSocketChannel
ServerSocketChannel serverChannel = ServerSocketChannel.open();
serverChannel.bind(new InetSocketAddress(8080));
serverChannel.configureBlocking(false);

// 注册Accept事件
serverChannel.register(selector, SelectionKey.OP_ACCEPT);

while (true) {
    selector.select(); // 阻塞直到有事件
    Set&lt;SelectionKey&gt; keys = selector.selectedKeys();
    Iterator&lt;SelectionKey&gt; iter = keys.iterator();
    
    while (iter.hasNext()) {
        SelectionKey key = iter.next();
        if (key.isAcceptable()) {
            // 处理新连接
        } else if (key.isReadable()) {
            // 处理读事件
        }
        iter.remove();
    }
}</code></pre>
                </div>
                
                <div class="mermaid">
                    graph LR
                    A[Client] --> B[SocketChannel]
                    B --> C[Selector]
                    C --> D[Thread]
                    D --> E[Buffer]
                    E --> F[Business Logic]
                </div>
            </div>
        </section>

        <!-- JUC Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-8 text-blue-800 border-b pb-4 flex items-center">
                    <i class="fas fa-cogs mr-3"></i>
                    <span>JUC：释放多核CPU潜力</span>
                </h2>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">线程池优化</h3>
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="bg-yellow-50 p-4 rounded-lg border-l-4 border-yellow-500">
                        <h4 class="font-bold mb-2">FixedThreadPool</h4>
                        <p class="text-gray-600">固定大小线程池</p>
                    </div>
                    <div class="bg-green-50 p-4 rounded-lg border-l-4 border-green-500">
                        <h4 class="font-bold mb-2">CachedThreadPool</h4>
                        <p class="text-gray-600">弹性线程池</p>
                    </div>
                    <div class="bg-purple-50 p-4 rounded-lg border-l-4 border-purple-500">
                        <h4 class="font-bold mb-2">ForkJoinPool</h4>
                        <p class="text-gray-600">分治任务线程池</p>
                    </div>
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">并发集合</h3>
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="p-4 rounded-lg bg-blue-50">
                        <h4 class="font-bold mb-2">ConcurrentHashMap</h4>
                        <p class="text-gray-600">高并发Map</p>
                    </div>
                    <div class="p-4 rounded-lg bg-green-50">
                        <h4 class="font-bold mb-2">CopyOnWriteArrayList</h4>
                        <p class="text-gray-600">读多写少List</p>
                    </div>
                    <div class="p-4 rounded-lg bg-purple-50">
                        <h4 class="font-bold mb-2">BlockingQueue</h4>
                        <p class="text-gray-600">阻塞队列（如ArrayBlockingQueue、LinkedBlockingQueue）</p>
                    </div>
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">原子变量与CAS</h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="p-4 rounded-lg bg-red-50">
                        <h4 class="font-bold mb-2">AtomicInteger</h4>
                        <p class="text-gray-600">原子整型</p>
                    </div>
                    <div class="p-4 rounded-lg bg-blue-50">
                        <h4 class="font-bold mb-2">AtomicReference</h4>
                        <p class="text-gray-600">原子引用</p>
                    </div>
                    <div class="p-4 rounded-lg bg-green-50">
                        <h4 class="font-bold mb-2">LongAdder</h4>
                        <p class="text-gray-600">高性能计数器</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- NIO + JUC实战 -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-8 text-blue-800 border-b pb-4 flex items-center">
                    <i class="fas fa-laptop-code mr-3"></i>
                    <span>NIO + JUC实战：高性能HTTP服务器</span>
                </h2>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">架构设计</h3>
                <ol class="list-decimal pl-6 mb-10 space-y-3">
                    <li><strong>NIO处理网络I/O</strong>：使用Selector监听连接和读写事件</li>
                    <li><strong>线程池处理业务逻辑</strong>：将耗时操作交给JUC线程池</li>
                    <li><strong>异步回调机制</strong>：通过Future或CompletableFuture实现异步处理</li>
                </ol>
                
                <div class="mermaid mb-10">
                    graph TB
                    subgraph NIO
                        A[Selector] --> B[Accept事件]
                        A --> C[Read事件]
                        A --> D[Write事件]
                    end
                    subgraph JUC
                        E[线程池] --> F[业务逻辑1]
                        E --> G[业务逻辑2]
                        E --> H[业务逻辑3]
                    end
                    B --> E
                    C --> E
                    D --> E
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">核心代码实现</h3>
                <div class="code-block p-6 mb-10">
                    <pre><code class="language-java">public class NioHttpServer {
    private static final ExecutorService workerPool = Executors.newFixedThreadPool(16);

    public static void main(String[] args) throws IOException {
        Selector selector = Selector.open();
        ServerSocketChannel serverChannel = ServerSocketChannel.open();
        serverChannel.bind(new InetSocketAddress(8080));
        serverChannel.configureBlocking(false);
        serverChannel.register(selector, SelectionKey.OP_ACCEPT);

        while (true) {
            selector.select();
            Set&lt;SelectionKey&gt; keys = selector.selectedKeys();
            Iterator&lt;SelectionKey&gt; iter = keys.iterator();

            while (iter.hasNext()) {
                SelectionKey key = iter.next();
                if (key.isAcceptable()) {
                    handleAccept(key, selector);
                } else if (key.isReadable()) {
                    handleRead(key);
                }
                iter.remove();
            }
        }
    }

    private static void handleAccept(SelectionKey key, Selector selector) throws IOException {
        ServerSocketChannel serverChannel = (ServerSocketChannel) key.channel();
        SocketChannel clientChannel = serverChannel.accept();
        clientChannel.configureBlocking(false);
        clientChannel.register(selector, SelectionKey.OP_READ);
    }

    private static void handleRead(SelectionKey key) {
        workerPool.submit(() -> {
            try {
                SocketChannel clientChannel = (SocketChannel) key.channel();
                ByteBuffer buffer = ByteBuffer.allocate(1024);
                clientChannel.read(buffer);
                buffer.flip();
                String request = new String(buffer.array()).trim();
                String response = processRequest(request);
                clientChannel.write(ByteBuffer.wrap(response.getBytes()));
                clientChannel.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }

    private static String processRequest(String request) {
        // 模拟业务处理
        return "HTTP/1.1 200 OK\r\n\r\nHello, World!";
    }
}</code></pre>
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">性能优化点</h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="p-4 bg-blue-50 rounded-lg">
                        <h4 class="font-bold mb-2">零拷贝技术</h4>
                        <p class="text-gray-600">使用FileChannel.transferTo减少内存拷贝</p>
                    </div>
                    <div class="p-4 bg-green-50 rounded-lg">
                        <h4 class="font-bold mb-2">缓冲区池化</h4>
                        <p class="text-gray-600">重用ByteBuffer对象</p>
                    </div>
                    <div class="p-4 bg-purple-50 rounded-lg">
                        <h4 class="font-bold mb-2">事件驱动模型</h4>
                        <p class="text-gray-600">避免线程阻塞</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Comparison -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-8 text-blue-800 border-b pb-4 flex items-center">
                    <i class="fas fa-chart-bar mr-3"></i>
                    <span>性能对比：传统BIO vs NIO+JUC</span>
                </h2>
                
                <div class="table-container">
                    <table>
                        <thead>
                            <tr>
                                <th class="font-semibold text-left">指标</th>
                                <th class="font-semibold text-left">BIO</th>
                                <th class="font-semibold text-left">NIO+JUC</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>线程数</td>
                                <td>1000</td>
                                <td>16</td>
                            </tr>
                            <tr>
                                <td>CPU利用率</td>
                                <td>30%</td>
                                <td>80%</td>
                            </tr>
                            <tr>
                                <td>内存占用</td>
                                <td>高</td>
                                <td>低</td>
                            </tr>
                            <tr>
                                <td>最大QPS</td>
                                <td>1200</td>
                                <td>9800</td>
                            </tr>
                            <tr>
                                <td>平均响应时间</td>
                                <td>150ms</td>
                                <td>20ms</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <div class="mermaid mt-10">
                    barChart
                    title 性能对比
                    x-axis 指标
                    y-axis 数值
                    series BIO
                    series NIO+JUC
                    data "线程数" 1000, 16
                    data "CPU利用率" 30, 80
                    data "最大QPS" 1200, 9800
                    data "响应时间" 150, 20
                </div>
            </div>
        </section>

        <!-- Advanced Topics -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-8 text-blue-800 border-b pb-4 flex items-center">
                    <i class="fas fa-rocket mr-3"></i>
                    <span>进阶话题：Reactor模式与Netty</span>
                </h2>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">Reactor模式</h3>
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="p-4 bg-blue-50 rounded-lg">
                        <h4 class="font-bold mb-2">单Reactor单线程</h4>
                        <p class="text-gray-600">简单但性能有限</p>
                    </div>
                    <div class="p-4 bg-green-50 rounded-lg">
                        <h4 class="font-bold mb-2">单Reactor多线程</h4>
                        <p class="text-gray-600">业务逻辑异步处理</p>
                    </div>
                    <div class="p-4 bg-purple-50 rounded-lg">
                        <h4 class="font-bold mb-2">主从Reactor多线程</h4>
                        <p class="text-gray-600">Netty采用的设计</p>
                    </div>
                </div>
                
                <h3 class="text-2xl font-bold mb-6 text-gray-800">Netty框架</h3>
                <div class="grid md:grid-cols-2 gap-6 mb-6">
                    <div>
                        <h4 class="font-bold text-lg mb-3 text-blue-700">核心组件</h4>
                        <ul class="list-disc pl-6 space-y-2">
                            <li><strong>Channel</strong>：网络操作抽象</li>
                            <li><strong>EventLoop</strong>：事件循环</li>
                            <li><strong>ChannelPipeline</strong>：处理器链</li>
                        </ul>
                    </div>
                    <div>
                        <h4 class="font-bold text-lg mb-3 text-green-700">优势</h4>
                        <ul class="list-disc pl-6 space-y-2">
                            <li><strong>高性能</strong>：基于NIO和零拷贝</li>
                            <li><strong>易用性</strong>：丰富的编解码器和处理器</li>
                            <li><strong>扩展性</strong>：支持自定义协议</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-8 text-blue-800 border-b pb-4 flex items-center">
                    <i class="fas fa-check-circle mr-3"></i>
                    <span>最佳实践与避坑指南</span>
                </h2>
                
                <div class="grid md:grid-cols-3 gap-8">
                    <div>
                        <h3 class="text-xl font-bold mb-4 text-gray-800">NIO最佳实践</h3>
                        <ol class="list-decimal pl-6 space-y-3">
                            <li><strong>合理设置Buffer大小</strong>：避免频繁分配和回收</li>
                            <li><strong>使用DirectBuffer</strong>：减少JVM堆内存拷贝</li>
                            <li><strong>处理半包/粘包问题</strong>：定义消息边界</li>
                        </ol>
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-bold mb-4 text-gray-800">JUC最佳实践</h3>
                        <ol class="list-decimal pl-6 space-y-3">
                            <li><strong>选择合适的线程池</strong>：根据任务类型调整参数</li>
                            <li><strong>避免锁竞争</strong>：使用无锁数据结构</li>
                            <li><strong>监控线程状态</strong>：使用JMX或Micrometer</li>
                        </ol>
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-bold mb-4 text-gray-800">常见陷阱</h3>
                        <ul class="list-disc pl-6 space-y-3">
                            <li><strong>Selector空轮询</strong>：Linux Epoll Bug导致CPU 100%</li>
                            <li><strong>线程池任务堆积</strong>：队列过大导致OOM</li>
                            <li><strong>回调地狱</strong>：过度嵌套回调降低可读性</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12 px-4">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                    <p class="text-gray-400 mt-1">专注分享高质量技术内容</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-300 hover:text-white transition-colors duration-300">
                        <i class="fas fa-external-link-alt mr-2"></i>www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. All Rights Reserved.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```